#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 5e5 + 5;
const int B = 131;
using ull = unsigned long long;

int n, m;
int tr[N][26], ed[N], tot;
void insert(string& s) {
  int p = 0;
  for (char c : s) {
    int x = c - 'a';
    if (!tr[p][x]) tr[p][x] = ++tot;
    p = tr[p][x];
  }
  ed[p] = 1;
}
bool search(string& s) {
  int p = 0;
  for (char c : s) {
    int x = c - 'a';
    if (!tr[p][x]) return false;
    p = tr[p][x];
    if (ed[p]) return true;
  }
  return false;
}
int tr2[N][26], sz[N], tot2;
void insert2(string& s) {
  int p = 0;
  for (char c : s) {
    int x = c - 'a';
    if (!tr2[p][x]) tr2[p][x] = ++tot2;
    p = tr2[p][x];
    sz[p]++;
  }
}
int search2(string& s) {
  int p = 0;
  for (char c : s) {
    int x = c - 'a';
    if (!tr2[p][x]) return 0;
    p = tr2[p][x];
  }
  int res = sz[p];
  if (!res) return 0;

  p = 0;
  for (char c : s) {
    int x = c - 'a';
    p = tr2[p][x];
    sz[p] -= res;
  }
  rep(i, 0, 25) tr2[p][i] = 0;
  return res;
}

int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  int ans = 0;
  while (n--) {
    int t;
    string s;
    cin >> t >> s;
    if (t == 1) {
      ans -= search2(s);
      insert(s);
      cout << ans << endl;
    } else {
      if (!search(s)) {
        ans++;
        insert2(s);
      }
      cout << ans << endl;
    }
  }
  return 0;
}